<?php
include '../src/Delegate.php';

testCreation();

function dumpResult($message, $result){
    $r = $result ? 'succes' : 'failed';
    print "<div><span>${message}</span>";

    $color = $result ? 'green' : 'red';
    print " <span style='background-color: ${color};'>${r}</span></div>";
}

function testCreation(){
    $result = false;

    //create a delegate
    $delegate = new Delegate();

    //create a new user object
    $user = new User();
    $user->email = 'bill@foo.com';
    $user->password = md5('bill');
    $user->name = 'Kill Bill ';
    $user->timezoneOffset = 2;

    //save user
    $delegate->userCreate($user);

    //load it from DB
    $tempUser = $delegate->userGetByEmail('bill@foo.com');

    //test if what we got is was we stored
    if($tempUser->password == md5('bill') && $tempUser->email == 'bill@foo.com'
            && $tempUser->name = 'Kill Bill' && $tempUser->timezoneOffset = 2){
        $result = true;
    }

    //now clean up the database
    $delegate->userDelete($tempUser);

    dumpResult(__METHOD__, $result);
}
?>
